//
//  goodsListViewController.m
//  ZPSALE
//
//  Created by tmosport on 14-7-1.
//  Copyright (c) 2014年 tmosport. All rights reserved.
//

#import "goodsListViewController.h"
#import "UIImageView+WebCache.h"


@interface goodsListViewController ()
@property(nonatomic,strong)NSArray *itemsArr;
@property(nonatomic,strong)NSDictionary *backDic;
@property (strong, nonatomic) IBOutlet UITableView *goodsListTv;

@end

@implementation goodsListViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavigationItem];
    [self dataInit];
    self.title = @"商品清单";
}
-(void)setNavigationItem {
    [self.navigationController.navigationBar setBackIndicatorImage:
     [UIImage imageNamed:@"return"]];
    [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:
     [UIImage imageNamed:@"return"]];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
}

-(void)leftBarbuttonItemClicked:(UIButton *)button {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)dataInit{
    NSDictionary *params = @{@"memberid": _memberId,
                             };
    AFHTTPRequestOperationManager *manger = [AFHTTPRequestOperationManager manager];
    [manger GET:APIURL@"sale/getCheckedProductList.json" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        _backDic = (NSDictionary *)responseObject;
        _itemsArr = _backDic[@"gtItems"];
        [self.goodsListTv reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        //DO:(@"Error:%@", error);
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_itemsArr count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dataDic = [_itemsArr objectAtIndex:indexPath.row];
    static NSString *cellIdentifi = @"reuseCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifi];
    
    UIImageView *pImg = (UIImageView *)[cell viewWithTag:1000];
    UILabel *brandName = (UILabel *)[cell viewWithTag:1001];
    UILabel *productName = (UILabel *)[cell viewWithTag:1002];
    UILabel *price  = (UILabel *)[cell viewWithTag:1003];
    
    [pImg sd_setImageWithURL:Return_imageUrl(dataDic[@"imageSource"], 180) placeholderImage:[UIImage imageNamed:@"noimage"] options:SDWebImageRetryFailed];
    brandName.text =[NSString stringWithFormat:@"%@",[dataDic valueForKey:@"brandname"]];
    productName.text = [NSString stringWithFormat:@"%@",[dataDic valueForKey:@"productname"]];
    price.text = [NSString stringWithFormat:@"￥%@",[dataDic valueForKey:@"price"]];

    return cell;
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
